﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.IO;
using System.Threading;
using ATM.DBlayer;
//using ATM.DBStublayer;

namespace ATM
{
    public class CurrencyTranLogic
    {

        CurrencyTrasDB db = new CurrencyTrasDB();
        AccountLogic ac = new AccountLogic();
        public int balance, checkEmtpy, calculate, result, checkWrong, checkmony;
        public bool calculate_call(string nameC, string mny)
        {
            // mny elly hwa elmabla3'
            // nameC elly hwa el accnumb
            int y;
            if (mny != "" && nameC != "")
            {
                if ((int.TryParse(mny, out y) && int.Parse(mny) > 0))
                {
                    db.calculate_trasform_to_bound(nameC);
                    calculate = int.Parse(mny) * db.buy;
                    checkWrong = 1;

                }
                else
                    checkWrong = 0;


                checkEmtpy = 1;
                return true;
            }
            else
            {
                checkEmtpy = 0;
                return false;
            }


        }

        public bool add_t_balnce(string AN)
        {
            if (string.IsNullOrEmpty(AN))
                return false;
            else
            {

                float DBbalance;

              DBbalance=  ac.GetBalance(int.Parse(AN));
                result = calculate + Convert.ToInt32(DBbalance);
                db.balanceChanges(AN, result);
                return true;
            }
        }

        public bool calculate_from_call(string CL, string mon)
        {

            if (mon != "" && CL != "")
            {
                int x;
                if ((int.TryParse(mon, out x) && int.Parse(mon) > 0))
                {
                    db.calculate_trasform_from_bound(CL);
                    if (db.sale != 0)
                        calculate = int.Parse(mon) / db.sale;
                    checkWrong = 1;
                }
                else
                {
                    checkWrong = 0;

                }

                checkEmtpy = 1;
                return true;

            }
            else
            {
                checkEmtpy = 0;

                return false;
            }


        }

        public bool take_f_balnce(string NA, string balan)
        {
            float DBbalance;
            
            if (NA != "" && balan != "")
            {
                //db.getBalance(NA);
              DBbalance=  ac.GetBalance(int.Parse(NA));
                if (int.Parse(balan) < DBbalance)
                {
                    result = Convert.ToInt32(DBbalance) - int.Parse(balan);
                    db.balanceChanges(NA, result);
                    checkmony = 1;
                    // return true;

                }
                else
                {
                    checkmony = 0;
                    //   return false;
                }
                return true;
            }
            else
            {
                return false;
            }
        }


    }
}
